import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  // 注册页面
  {
    path: '/zhuce',
    component: () => import('@/views/zhuce/index'),
    hidden: true,
    meta: { title: '注册', icon: 'user' }
  },

  {
    path: '/login',
    component: () => import('@/views/login/index'),
    /**
     * hidden：是一个自定义属性
     * 作用：控制当前路由是否渲染到系统导航列表中的
     *  值为 true 表示隐藏
     * */
    hidden: true,
    meta: { title: '登录', icon: 'user' }
  },

  // {
  //   path: '/houseManage',
  //   component: () => import('@/views/houseManage/index'),
  //   hidden: true
  // },
  // {
  //   path: '/rolesManage',
  //   component: () => import('@/views/rolesManage/index'),
  //   hidden: true
  // },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      /**
       * meta 是路由内置的属性  ---- 叫路由元信息
       * 作用：用于保存数据
       *
       * meta里面的所有属性都是自定义的
       * 这里的title是用于渲染在导航中的标题
       * icon是用户渲染到导航中的图标
       * */
      meta: { title: '首页管理', icon: 'dashboard' }
    }]
  }

  // 404 page must be placed at the end !!!

]

// 导入动态路由对象
import fangchangRouter from './modules/fangchang'
import fenleiRouter from './modules/fenlei'
import jingjiRouter from './modules/jingji'
import jueseRouter from './modules/juese'
import kehuRouter from './modules/kehu'
import quanxianRouter from './modules/quanxian'
import yemianRouter from './modules/yemian'
import yuangongRouter from './modules/yuangong'

// asyncRoute用于保存动态路由的数组
export const asyncRoutes = [
  fangchangRouter,
  fenleiRouter,
  jingjiRouter,
  jueseRouter,
  kehuRouter,
  quanxianRouter,
  yemianRouter,
  yuangongRouter
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  base: 'admin',
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
